﻿$(function(){

	$("#add_document").click(function(){
		var id=$("#document_tr:first").children();
		var tr = $(id).clone();
		//alert(tr.html());
		$("#dome_table").append(tr);
		$("#dome_table tr:last input").each(function(){
			$(this).val("");
		});
		//$("#dome_table tr:last td:last").html("");
		tr.show();
	});
	
	
	
	
	
	 $("tr").children(".niu").dblclick(function() {   
			var tdObj = $(this);   
			var souText = tdObj.html();   // 原来的内容   
			var input = $("<textarea >" + souText + "</textarea>");   
		
			// 设置文本框的宽   
			input.width(tdObj.width());   
			// 设置文本框的点击事件   
			input.dblclick(function() {   
				return false;   
			});   
			// 设置文本框的样式   
			input.css({ "border-width": 0 });   
			// 将文本框替换当前td的内容   
			tdObj.html(input);   
			// 触发文本框的focus事件后再触发select事件   
			input.trigger("focus").trigger("select");   
			// 文件框的焦点失去事件, 把文本框中填写的内容变成   
			input.blur(function() {   
				// 查找当前td的前一个td中的内容, 即当前行的序号 
				//alert(input.val());
				//alert(souText);
				if(input.val()!=souText){
					
					var tableName = tdObj.attr("tableName");
					var fieldName = tdObj.attr("fieldName");
					var fieldValue = encodeURIComponent(input.val());
					var keyName = tdObj.attr("keyName");
					var keyValue = tdObj.attr("keyValue");
					var s = "tableName="+tableName+"&fieldName="+fieldName+"&fieldValue="+fieldValue+"&keyName="+keyName+"&keyValue="+keyValue;
					//alert(s);
					var re = saveFieldData(s);
					if(re==1){
						tdObj.css("background-color","#eafcd4");
					}else{
						tdObj.css("background-color","#ff0000");
					}
				}
				tdObj.html(input.val());
				// 查找当前td的前一个td中的内容, 即当前行的序号 
			//alert(tdObj.attr("idvalue"));
			});   
			// 处理文本框中键盘按键事件, Enter 13确认,Esc 27取消
			input.keydown(function(event) {
			var keyCode = event.keyCode;   
			if (keyCode == 13) {   
				// 按下回车   
				tdObj.html(input.val());   
				// 查找当前td的前一个td中的内容, 即当前行的序号   
				//alert(tdObj.prev().text());  
				
			}   
			if (keyCode == 27) {   
				// 按下Esc   
				tdObj.html(souText);   
			}   
			});   
    }); 
	
	
	$("[id='isnullchecked']").click(function(){
			var tdObj = $(this);
			var tableName = tdObj.attr("tableName");
			var fieldName = tdObj.attr("fieldName");
			var fieldValue = tdObj.attr("checked")==true?1:0;
			var keyName = tdObj.attr("keyName");
			var keyValue = tdObj.attr("keyValue");
			var s = "tableName="+tableName+"&fieldName="+fieldName+"&fieldValue="+fieldValue+"&keyName="+keyName+"&keyValue="+keyValue;
			
			var re = saveFieldData(s);
			if(re==1){
				tdObj.parents("td:first").css("background-color","#eafcd4");
			}else{
				tdObj.parents("td:first").css("background-color","#ff0000");
			}	
	});  
	
	$("[id='dataType']").change(function(){
			var tdObj = $(this);
			var tableName = tdObj.attr("tableName");
			var fieldName = tdObj.attr("fieldName");
			var fieldValue = $(this).val();
			var keyName = tdObj.attr("keyName");
			var keyValue = tdObj.attr("keyValue");
			var s = "tableName="+tableName+"&fieldName="+fieldName+"&fieldValue="+fieldValue+"&keyName="+keyName+"&keyValue="+keyValue;
			var re = saveFieldData(s);
			if(re==1){
				tdObj.parents("td:first").css("background-color","#eafcd4");
			}else{
				tdObj.parents("td:first").css("background-color","#ff0000");
			}	
	}); 
	
	
			$("[id='tag']").change(function(){
			var tdObj = $(this);
			var tableName = tdObj.attr("tableName");
			var fieldName = tdObj.attr("fieldName");
			var fieldValue = $(this).val();
			var keyName = tdObj.attr("keyName");
			var keyValue = tdObj.attr("keyValue");
			var s = "tableName="+tableName+"&fieldName="+fieldName+"&fieldValue="+fieldValue+"&keyName="+keyName+"&keyValue="+keyValue;
			var re = saveFieldData(s);
			if(re==1){
				tdObj.parents("td:first").css("background-color","#eafcd4");
			}else{
				tdObj.parents("td:first").css("background-color","#ff0000");
			}	
	}); 
	
	
	



});



   	
function saveFieldData(s){
	return doPost("/hfmanager/base_source/list.do","action=updateFieldValue&"+s);
}


function delDocument(o){
	$(o).parents("tr:first").remove();	
}
   	
	
